<?php

namespace App\Http\Controllers\Web\Doctor;

use App\Base\BaseController;
use App\Helper\ErrorHelper;
use App\Models\Doctor\Doctor;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

//use Illuminate\Routing\Controller as BaseController;

class DoctorController extends BaseController
{

    public function doctorList(Request $request)
    {
        $doctors = DB::table('doctor')->paginate(10);
//        $doctors = Doctor::paginate(10);dd($doctors);
//        $doctors = Doctor::simplepaginate(15);dd($doctors);
//        $results->count();//每页显示记录
//        $results->currentPage();//当前页
//        $results->firstItem();//获取结果集中第一条数据的结果编号
//        $result->total();//共有多少条记录 simplepaginate不可用
//        $result->lastPage();//获取最后一页页面 simplepaginate不可用
//        $results->getOptions() ;//获取分页选项
//        $results->getUrlRange($start, $end) ;//创建分页 URL 的范围
//        $results->hasMorePages() ;// 判断是否还有足够多的项目用于分页
//        $results->lastItem()  ;//获取结果集分片中最后一项的编号
//        $results->nextPageUrl();// 获取下一页的 URL
//        $results->onFirstPage() ;//判断是否在第一页
//        $results->perPage() ;//每页显示的项目数
//        $results->previousPageUrl() ;//获取上一页的 URL
//        $results->url($page)  ;//获取给定页码的分页 URL



        return view('doctor.doctor_list', [
            'doctors' => $doctors
        ]);
    }

    public function doctorListData(Request $request)
    {
        $page = $request->input('page', 1);
        $limit = $request->input('limit', 20);

        $count = Doctor::count();
        $doctors = Doctor::offset($page)->limit($limit)->get();

        $data = [
            "code"  => 0,
            "msg"   => '',
            "count" => $count,
            "data"  => $doctors
        ];
        return response()->json($data);
    }
}
